﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Collections;

/// <summary>
/// Summary description for XL_KH
/// </summary>
public class XL_SP
{
    protected DataRow Dong;
    protected static String Tenbang = "SAN_PHAM";

    public string MaSP
    {
        get
        {
            return this.Dong["Ma_sp"].ToString();
        }
        set
        {
            this.Dong["Ma_sp"] = value;
        }
    }

    
    public string TenSP
    {
        get
        {
            return this.Dong["Ten_sp"].ToString();
        }
        set
        {
            this.Dong["Ten_sp"] = value;
        }
    }

    public int GiaSP
    {
        get
        {
            return (int)this.Dong["Gia_sp"];
        }
        set
        {
            this.Dong["Gia_sp"] = value;
        }
    }

  
    public string MotaSP
    {
        get
        {
            return this.Dong["Mota_sp"].ToString();
        }
        set
        {
            this.Dong["Mota_sp"] = value;
        }
    }

    public string HinhSP
    {
        get
        {
            return this.Dong["Hinh_sp"].ToString();
        }
        set
        {
            this.Dong["Hinh_sp"] = value;
        }
    }

    public DateTime Ngaynhan_SP
    {
        get
        {
            return (DateTime)this.Dong["Ngaytiepnhan_sp"];
        }
        set
        {
            this.Dong["Ngaytiepnhan_sp"] = value;
        }
    }


    public int SoluongSP
    {
        get
        {
            return (int)this.Dong["Soluong_sp"];
        }
        set
        {
            this.Dong["Soluong_sp"] = value;
        }
    }

    public int SoluongbanSP
    {
        get
        {
            return (int)this.Dong["soluongban_sp"];
        }
        set
        {
            this.Dong["soluongban_sp"] = value;
        }
    }

    public long Soluotxem_SP
    {
        get
        {
            return (long)this.Dong["soluotxem_sp"];
        }
        set
        {
            this.Dong["soluotxem_sp"] = value;
        }
    }

    public string DactinhSP
    {
        get
        {
            return this.Dong["Dactinh_sp"].ToString();
        }
        set
        {
            this.Dong["Dactinh_sp"] = value;
        }
    }

    public string MaloaiSP
    {
        get
        {
            return this.Dong["ML"].ToString();
        }
        set
        {
            this.Dong["ML"] = value;
        }
    }

    public string MaHangSX
    {
        get
        {
            return this.Dong["MHSX"].ToString();
        }
        set
        {
            this.Dong["MHSX"] = value;
        }
    }

    public string MaXX
    {
        get
        {
            return this.Dong["MXX"].ToString();
        }
        set
        {
            this.Dong["MXX"] = value;
        }
    }

     public XL_SP()
    {
        String sql="select * from " + Tenbang;
        DataTable Bang  = DataProvider.ExecuteStructureQuery(sql);
        Dong = Bang.NewRow();
        Bang.Rows.Add(Dong);
    }

    public XL_SP(DataRow DongN)
	{
		//
		// TODO: Add constructor logic here
		//
        this.Dong = DongN;
	}

    //public static ArrayList Doc_danh_sach()
    //{
    //    ArrayList Kq = new ArrayList();
    //    string sql = "Select * ";
    //    sql += " From DON_HANG dh,TAI_KHOAN tk ";
    //    sql += " Where dh.mtk = tk.mtk";
    //    DataTable Bang = DataProvider.ExecuteQuery(sql);
    //    foreach (DataRow DT in Bang.Rows)
    //    {
    //        XL_DH LTK = new XL_DH(DT);
    //        Kq.Add(LTK);
    //    }
    //    return Kq;

    //}

    public static ArrayList TimSP_theo_MHSX_MXX_ML(String MHSX,String MXX,String ML)
    {
        //String sql = "select * from SAN_PHAM sp,HANG_SAN_XUAT hsx,XUAT_XU xx,LOAI_SP lsp ";
        //sql += "where sp.MHSX = hsx.MHSX and sp.MXX = xx.MXX and sp.ML = lsp.ML ";
        ArrayList DS_SP = new ArrayList();
        String sql = "select * from SAN_PHAM ";
        sql += "where MHSX='XXX' and MXX='YYY' and ML='ZZZ'";
        sql = sql.Replace("XXX",MHSX);
        sql = sql.Replace("YYY", MXX);
        sql = sql.Replace("ZZZ", ML);
        DataTable Bang = DataProvider.ExecuteQuery(sql);
        foreach (DataRow DT in Bang.Rows)
        {
            DS_SP.Add(new XL_SP(DT));
        }
        return DS_SP;
        
    }

    public static XL_SP TimSP_theo_MSP(String MASP) // Duy nhat
    {
        String sql = "select * from SAN_PHAM ";
        sql += "where Ma_sp='XXX'";
        sql = sql.Replace("XXX", MASP);
        
        DataTable Bang = DataProvider.ExecuteQuery(sql);
        if (Bang.Rows.Count > 0)
        {
            return new XL_SP(Bang.Rows[0]);
        }
        return null;

    }


  

    public void Ghi() // Ghi tung dong
    {
        //String sql = "select * from " + Tenbang;
        //sql += " Where MTK = " + this.MTK;
        //DataTable BDH = DataProvider.ExecuteQuery(sql);
        //DataRow DH = BDH.Rows[0];
       
        //DH["MDH"] = this.MaDH;
        //DH["Ngaydat"] = this.Ngaydat;
        //DH["Tinhtrang"] = this.TinhtrangTT;

        //Ghi Bang
        
        DataProvider.Save(this.Dong, Tenbang);

    }
    public void Xoa()
    {

        //String sql = "select * from " + Tenbang;
        //sql += " Where MTK = " + this.MTK;
        //DataTable BDH = DataProvider.ExecuteQuery(sql);
        //DataRow DH = BDH.Rows[0];
       
        DataProvider.Delete(this.Dong, Tenbang);

    }

}

  